//package com.shanwen.shopping.activity;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.os.Bundle;
//import android.text.Html;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import com.classic.core.utils.DataUtil;
//import com.shanwen.shopping.R;
//import com.shanwen.shopping.adapter.GoodsPayAdapter;
//import com.shanwen.shopping.consts.Consts;
//import com.shanwen.shopping.dao.ShoppingCartHelper;
//import com.shanwen.shopping.dao.ShoppingCartItem;
//import com.shanwen.shopping.dialog.QrCodeDialog;
//import com.shanwen.shopping.pay.PayUtil;
//import com.shanwen.shopping.utils.Utils;
//import com.shanwen.shopping.view.MyListView;
//
//import org.simple.eventbus.Subscriber;
//import org.simple.eventbus.ThreadMode;
//
//import java.util.ArrayList;
//
//import butterknife.BindView;
//import butterknife.ButterKnife;
//import butterknife.OnClick;
//
///**
// * 商品支付页面
// */
//public class GoodsPayActivity extends AppBaseActivity {
//    private static final String PARAMS_GOODS = "goods";
//    private static final String PARAMS_HAS_SHOPPING_CART = "hasShoppingCart";
//    @BindView(R.id.goods_pay_note_et)
//    EditText etNote;
//    @BindView(R.id.goods_pay_lv)
//    MyListView payListView;
//    @BindView(R.id.goods_pay_total_price)
//    TextView tvTotalPrice;
//    @BindView(R.id.goods_pay_pay_btn)
//    TextView btnPay;
//    @BindView(R.id.tvPersonInfo)
//    TextView tvPersonInfo;
//    @BindView(R.id.tvPersonInfo2)
//    TextView tvPersonInfo2;
//    @BindView(R.id.et_prison_num)
//    EditText etPrisonNum;
//    @BindView(R.id.et_prison_phone)
//    EditText etPrisonPhone;
//    @BindView(R.id.ivGoodsBack)
//    ImageView ivGoodsBack;
//    @BindView(R.id.ivGoodsChart)
//    ImageView ivGoodsChart;
//    @BindView(R.id.ivGoodsTop)
//    ImageView ivGoodsTop;
//
//
//    private ArrayList<ShoppingCartItem> items;
//    private GoodsPayAdapter payAdapter;
//    private boolean hasShoppingCart;
//    private boolean paySuccess;
//    private QrCodeDialog qrCodeDialog;
//
//    //    public static void start(Activity activity, ArrayList<ShoppingCartItem> items) {
////        if (null != activity && !DataUtil.isEmpty(items)) {
////            Intent intent = new Intent(activity, GoodsPayActivity.class);
////            intent.putExtra(PARAMS_GOODS, items);
////            activity.startActivity(intent);
////        }
////    }
//    public static void start(Activity activity, ArrayList<ShoppingCartItem> items, boolean hasShoppingCart) {
//        if (null != activity && !DataUtil.isEmpty(items)) {
//            Intent intent = new Intent(activity, GoodsPayActivity.class);
//            intent.putExtra(PARAMS_GOODS, items);
//            intent.putExtra(PARAMS_HAS_SHOPPING_CART, hasShoppingCart);
//            activity.startActivity(intent);
//        }
//    }
//
//    @Override
//    public int getLayoutResId() {
//        return R.layout.activity_goods_pay;
//    }
//
//    @Override
//    public void initView() {
//        super.initView();
////        setTitle("商品支付");
//        setBackEnabled(true);
//        tvPersonInfo2.setText(Html.fromHtml("<font  color=\"#666666\">带</font>" +
//                "<font  color=\"#FF432F\">*</font>" +
//                "<font  color=\"#666666\">为必填项</font>"));
//        setShoppingCartEnabled(false);
//        if (getIntent().hasExtra(PARAMS_GOODS) && getIntent().hasExtra(PARAMS_HAS_SHOPPING_CART)) {
//            items = (ArrayList<ShoppingCartItem>) getIntent().getSerializableExtra(PARAMS_GOODS);
//            hasShoppingCart = getIntent().getBooleanExtra(PARAMS_HAS_SHOPPING_CART, false);
//        }
//        if (DataUtil.isEmpty(items)) {
//            finish();
//            return;
//        }
//
//        payAdapter = new GoodsPayAdapter(activity, R.layout.goods_pay_item, items);
//        payListView.setAdapter(payAdapter);
////        calculateTotalPrice();
//        totalPrice = payAdapter.calculateTotalPrice();
//        priceChange(totalPrice);
//    }
//
//    private String totalPrice;
//    /**
//     * 计算总价格
//     */
////    private void calculateTotalPrice(){
////        int value = 0;
////        for(ShoppingCartItem item:items){
////            value += item.getPrice() * item.getNumber();
////        }
////        totalPrice = MoneyUtil.divide(value, 100).toString();
////        tvTotalPrice.setText(new StringBuilder(Consts.MONEY_PREFIX).append(MoneyUtil.replace(totalPrice)));
////    }
//
//    private String name;
//    private String address;
//    private String age;
//    private String code;
//    private String message;
//    private String prisonNum;
//    private String phone;
//
//    private boolean verifyData() {
////        message = etCode.getText().toString().trim();
////        name = etName.getText().toString().trim();
////        if (TextUtils.isEmpty(name)) {
////            Utils.showToast(activity, "请输入犯人编号");
////            return false;
////        }
////        address = etAddress.getText().toString().trim();
////        if (TextUtils.isEmpty(address)) {
////            Utils.showToast(activity, "请输入地址");
////            return false;
////        }
////        age = etAge.getText().toString().trim();
////        if (TextUtils.isEmpty(age)) {
////            Utils.showToast(activity, "请输入年龄");
////            return false;
////        }
////        code = etCode.getText().toString().trim();
//        //if(TextUtils.isEmpty(code)){
//        //    Utils.showToast(activity,"请输入邮编");
//        //    return false;
//        //}
//        prisonNum = etPrisonNum.getText().toString();
//        phone = etPrisonPhone.getText().toString();
//        if (TextUtils.isEmpty(prisonNum)) {
//            Utils.showToast(activity, "请输入犯人编号");
//            return false;
//        }
//        if (TextUtils.isEmpty(phone)) {
//            Utils.showToast(activity, "请输入家属手机");
//            return false;
//        }
//        return true;
//    }
//
//
//    private void pay() {
//        if (!verifyData()) return;
//        qrCodeDialog = new QrCodeDialog(this)
//                .setTitle("付款二维码")
//                .setHintText("请扫描上方二维码完成付款")
//                .setCanceledOnTouch(false)
//                .setOnClickListener(new QrCodeDialog.OnClickListener() {
//                    @Override
//                    public void confirm() {
//                        qrCodeDialog.dismiss();
//                    }
//
//                    @Override
//                    public void cancel() {
//                        qrCodeDialog.dismiss();
//                    }
//                });
//        qrCodeDialog.show();
//       /* final JSONObject addressJson = Utils.getAddressJson(name, address, code);
//        final JSONArray arr = new JSONArray();
//        for (ShoppingCartItem item : items) {
//            final JSONObject goodsJson = Utils.getGoodsListJson(item.getGoodsId(), item.getNumber(),
//                    item.getTitle(), item.getCoverUrl(),
//                    Utils.getSkuProp(item.getSkuPropName(), item.getSkuPropValue()), item.getSkuId());
//            arr.put(goodsJson);
//        }
//        final String json = Utils.getonfirmOrderJson(addressJson, arr, phone,prisonNum,message);
//        ActionHelp.confirmOrder(activity, json,
//                new ObjectCallback<OrderInfo>() {
//
//                    @Override
//                    public void onSuccess(OrderInfo response) {
//                        Logger.d("确认订单成功");
//                        if (null != response) {
//                            //TODO 修改价格
//                            PayUtil.pay(activity, response.orderSerial, items.get(0).getTitle(), response.orderDesc, "0.01");
////                            PayUtil.pay(activity, response.orderSerial, items.get(0).getTitle(), response.orderDesc, totalPrice);
//                        }
//                    }
//
//                    @Override
//                    public Class<OrderInfo> getType() {
//                        return OrderInfo.class;
//                    }
//
//                    @Override
//                    public void onError(int code, String errorMessage) {
//                        super.onError(code, errorMessage);
//                        Logger.e("确认订单失败:" + code + "," + errorMessage);
//                        Utils.showToast(activity, "订单提交失败");
//                    }
//                });*/
//
//    }
//
//    @OnClick({R.id.goods_pay_pay_btn, R.id.ivGoodsBack, R.id.ivGoodsTop, R.id.ivGoodsChart})
//    public void onClick(View v) {
//        switch (v.getId()) {
//            case R.id.goods_pay_pay_btn:
//                pay();
//                break;
//            case R.id.ivGoodsBack:
//                finish();
//                break;
//            case R.id.ivGoodsTop:
//                payListView.scrollTo(0, 0);
//                break;
//            case R.id.ivGoodsChart:
//                startActivity(activity, ShoppingCartActivity.class);
//                break;
//        }
//    }
//
//    @Subscriber(tag = Consts.EVENT_QUANTITY_CHANGE, mode = ThreadMode.MAIN)
//    public void priceChange(String totalPrice) {
//        this.totalPrice = totalPrice;
//        tvTotalPrice.setText(new StringBuilder(Consts.MONEY_PREFIX).append(totalPrice));
//    }
//
//    @Subscriber(tag = PayUtil.PAY_SUCCESS, mode = ThreadMode.MAIN)
//    public void paySuccess(String params) {
//        if (hasShoppingCart) {
//            ArrayList<Long> ids = new ArrayList<>();
//            for (ShoppingCartItem item : items) {
//                ids.add(item.getId());
//            }
//            ShoppingCartHelper.getInstance(activity).delete(ids);
//        }
//        paySuccess = true;
//        finish();
//    }
//
//    @Override
//    protected void onDestroy() {
//        if (!hasShoppingCart) {
//            ShoppingCartHelper helper = ShoppingCartHelper.getInstance(activity);
//            ShoppingCartItem shoppingCartItem = items.get(0);
//            if (null == shoppingCartItem) return;
//            long id = helper.exists(shoppingCartItem);
//            if (!paySuccess) {
//                if (id > 0) {
//                    shoppingCartItem.setId(id);
//                    helper.update(shoppingCartItem);
//                } else {
//                    helper.add(shoppingCartItem);
//                }
//            } else {
//                if (id > 0) {
//                    helper.delete(id);
//                }
//            }
//        }
//        super.onDestroy();
//    }
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        // TODO: add setContentView(...) invocation
//        ButterKnife.bind(this);
//    }
//
//
////    private static final String PARAMS_GOODSDETAIL = "GoodsDetail";
////    private static final String PARAMS_NUMBER = "number";
////    private static final String PARAMS_SKUID = "skuId";
////    private static final String PARAMS_SKUPROP_NAME = "skuPropName";
////    private static final String PARAMS_SKUPROP_VALUE = "skuPropValue";
////    private GoodsDetail goodsDetail;
////    private int number;
////    private long skuId;
////    private String skuPropName;
////    private String skuPropValue;
////    /**
////     * 商品支付页面
////     * @param activity
////     * @param goodsDetail 商品详情对象
////     * @param number 购买数量
////     * @param skuId sku主键id
////     * @param skuPropName 用户购买商品的最终sku属性名称,如:{“颜色”:”白色”}
////     * @param skuPropValue 用户购买商品的最终sku属性值,如:{“颜色”:”白色”}
////     */
////    public static void start(Activity activity, GoodsDetail goodsDetail,int number,
////                             long skuId,String skuPropName,String skuPropValue) {
////        if (null != activity && null != goodsDetail) {
////            Intent intent = new Intent(activity, GoodsPayActivity.class);
////            intent.putExtra(PARAMS_GOODSDETAIL, goodsDetail);
////            intent.putExtra(PARAMS_NUMBER, number);
////            intent.putExtra(PARAMS_SKUID, skuId);
////            intent.putExtra(PARAMS_SKUPROP_NAME, skuPropName);
////            intent.putExtra(PARAMS_SKUPROP_VALUE, skuPropValue);
////            activity.startActivity(intent);
////        }
////    }
////    @Override
////    public void initView() {
////        super.initView();
////        number = getIntent().getIntExtra(PARAMS_NUMBER, 1);
////        skuId = getIntent().getLongExtra(PARAMS_SKUID, 0L);
////        if(getIntent().hasExtra(PARAMS_SKUPROP_NAME) && getIntent().hasExtra(PARAMS_SKUPROP_VALUE)
////                && getIntent().hasExtra(PARAMS_GOODSDETAIL)){
////            goodsDetail = (GoodsDetail) getIntent().getSerializableExtra(PARAMS_GOODSDETAIL);
////            skuPropName = getIntent().getStringExtra(PARAMS_SKUPROP_NAME);
////            skuPropValue = getIntent().getStringExtra(PARAMS_SKUPROP_VALUE);
////        }
////        if (null == goodsDetail || skuId<=0 || TextUtils.isEmpty(skuPropName) ||
////                TextUtils.isEmpty(skuPropValue)) {
////            finish();
////            return;
////        }
////    }
//}
